package com.ykt.model;

import java.util.List;

import com.jfinal.plugin.activerecord.Page;
import com.ykt.interceptor.Seach;

public class CustomerAddress extends SeachModel<CustomerAddress>{

	private static final long serialVersionUID = 1L;
	public static final CustomerAddress dao = new CustomerAddress();
	
	public Page<CustomerAddress> paginate(int pageNumber,int rows,Seach seach){
		String select="select a.*,c.username as username,c.realname as realname ";
		String sqlExceptSelect=" from customer_address a left join customer c on a.customer_id = c.id "
				+ " left join shop s on a.shop_id = s.id where 1=1 ";
		return paginateBySelect(select, sqlExceptSelect, pageNumber, rows, seach);
	}
	public Customer getCustomer(){
		return Customer.dao.findById(get("customer_id"));
	}
	/**
	 * 查找指定客户的地址
	 * @param customerID
	 * @return
	 */
	public List<CustomerAddress> findByCustomerId(int customerID){
		return dao.find("select * from customer_address  where customer_id=? order by id desc",customerID);
	}
	/**
	 * 查找第一个地址
	 * @param customerID
	 * @return
	 */
	public CustomerAddress findFirstByCustomerId(int customerID){
		return dao.findFirst("select * from customer_address  where customer_id=? order by id desc",customerID);
	}
}
